package com.briup.jz.service.impl;

import com.briup.jz.bean.BasePrivilege;
import com.briup.jz.bean.BasePrivilegeExample;
import com.briup.jz.dao.BasePrivilegeMapper;
import com.briup.jz.service.IBasePrivilegeService;
import com.briup.jz.utils.CustomerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BasePrivilegeServiceImpl implements IBasePrivilegeService {
    @Autowired
    private BasePrivilegeMapper basePrivilegeMapper;
    @Override
    public void saveOrUpdate(BasePrivilege basePrivilege) throws CustomerException {
        if(basePrivilege.getId()==null){
            basePrivilegeMapper.insert(basePrivilege);
        }else {
            BasePrivilege basePrivilege1 = basePrivilegeMapper.selectByPrimaryKey(basePrivilege.getId());
            if (basePrivilege1==null){
                throw new CustomerException("该的Privilege不存在");
            }
            basePrivilegeMapper.updateByPrimaryKey(basePrivilege);
        }
    }

    @Override
    public List<BasePrivilege> query() {
        BasePrivilegeExample example = new BasePrivilegeExample();
        return basePrivilegeMapper.selectByExample(example);
    }

    @Override
    public void deleteById(long id) {
        BasePrivilege basePrivilege = basePrivilegeMapper.selectByPrimaryKey(id);
        if (basePrivilege==null){
            throw new CustomerException("该Privilege不存在");
        }
        basePrivilegeMapper.deleteByPrimaryKey(id);
    }
}
